From 04276ec1bf343f5494fb95e7ad6e1287ba2dc6ed Mon Sep 17 00:00:00 2001 From: robertlipe Date: Fri, 12 Jul 2013 01:21:00 +0000 Subject: [PATCH] From Gerhard Olsson: Three parts. The second/third part is normally inactive in the code. gtrnctr.c Average Cadence in laps was handled as floats with one decimal but the xml format specifies char. Some programs therefore failed to parse the generated xml CadenceValue_t in http://www8.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd jeeps Cadence is invalid if it is 255 in Garmin USB. This is handled for track points but not for lap data. garmin.c (inactive) function read_lap_as_track() was not updated to the new string handling --- gpsbabel/garmin.cc | 22 +++++++++++----------- gpsbabel/gpx.cc | 8 +++++--- gpsbabel/gtrnctr.cc | 4 ++-- gpsbabel/jeeps/gpsapp.cc | 12 +++++++++--- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/gpsbabel/garmin.cc b/gpsbabel/garmin.cc index 60eadbf65..fda06a80f 100644 --- a/gpsbabel/garmin.cc +++ b/gpsbabel/garmin.cc @@ -592,6 +592,7 @@ lap_read_as_track(void) int trk_num = 0; int index; int i; + char tbuf[128]; ntracks = GPS_Command_Get_Lap(portname, &array, waypt_read_cb); if (ntracks <= 0) { @@ -617,8 +618,8 @@ lap_read_as_track(void) trk_head = route_head_alloc(); /*For D906, we would like to use the track_index in the last packet instead...*/ trk_head->rte_num = ++trk_num; - trk_head->rte_name = xmalloc(32); - strftime(trk_head->rte_name, 32, "%Y-%m-%dT%H:%M:%SZ", stmp); + strftime(tbuf, 32, "%Y-%m-%dT%H:%M:%SZ", stmp); + trk_head->rte_name = xstrdup(tbuf); track_add_head(trk_head); wpt = waypt_new(); @@ -631,13 +632,12 @@ lap_read_as_track(void) wpt->creation_time = array[i]->start_time; wpt->microseconds = 0; - wpt->shortname = xmalloc(8); - sprintf(wpt->shortname, "#%d-0", index); - wpt->description = xmalloc(128); - sprintf(wpt->description, "D:%f Cal:%d MS:%f AH:%d MH:%d AC:%d I:%d T:%d", + sprintf(tbuf, "#%d-0", index); + wpt->shortname = xstrdup(tbuf); + sprintf(tbuf, "D:%f Cal:%d MS:%f AH:%d MH:%d AC:%d I:%d T:%d", array[i]->total_distance, array[i]->calories, array[i]->max_speed, array[i]->avg_heart_rate, array[i]->max_heart_rate, array[i]->avg_cadence, array[i]->intensity, array[i]->trigger_method); - + wpt->description = xstrdup(tbuf); track_add_wpt(trk_head, wpt); } /*Allow even if no correct location, no skip if invalid */ @@ -655,13 +655,13 @@ lap_read_as_track(void) wpt->creation_time = array[i]->start_time + array[i]->total_time/100; wpt->microseconds = 10000*(array[i]->total_time % 100); /*Add fields with no mapping in the description */ - wpt->shortname = xmalloc(8); - sprintf(wpt->shortname, "#%d", index); - wpt->description = xmalloc(128); - sprintf(wpt->description, "D:%f Cal:%d MS:%f AH:%d MH:%d AC:%d I:%d T:%d (%f,%f)", + sprintf(tbuf, "#%d", index); + wpt->shortname = xstrdup(tbuf); + sprintf(tbuf, "D:%f Cal:%d MS:%f AH:%d MH:%d AC:%d I:%d T:%d (%f,%f)", array[i]->total_distance, array[i]->calories, array[i]->max_speed, array[i]->avg_heart_rate, array[i]->max_heart_rate, array[i]->avg_cadence, array[i]->intensity, array[i]->trigger_method, array[i]->begin_lon, array[i]->begin_lat); + wpt->description = xstrdup(tbuf); track_add_wpt(trk_head, wpt); } diff --git a/gpsbabel/gpx.cc b/gpsbabel/gpx.cc index 245839b4b..dcc878e19 100644 --- a/gpsbabel/gpx.cc +++ b/gpsbabel/gpx.cc @@ -994,11 +994,13 @@ gpx_end(void* data, const XML_Char* xml_el) } break; case tt_cache_desc_long: - rtrim(cdatastrp); - if (cdatastrp[0]) { + { geocache_data* gc_data = waypt_alloc_gc_data(wpt_tmp); gc_data->desc_long.is_html = cache_descr_is_html; - gc_data->desc_long.utfstring = cdatastrp; +// FIXME: Forcing a premature conversion here saves 4% on GPX read times +// on large PQs. Once cdatastrp becomes real QString this is just (minimal) +// overhead. + gc_data->desc_long.utfstring = QString(cdatastrp).trimmed(); } break; case tt_cache_desc_short: diff --git a/gpsbabel/gtrnctr.cc b/gpsbabel/gtrnctr.cc index ea1fce0e8..0805660a6 100644 --- a/gpsbabel/gtrnctr.cc +++ b/gpsbabel/gtrnctr.cc @@ -327,7 +327,7 @@ gtc_waypt_pr(const waypoint* wpt) if (wpt->power) { gtc_write_xml(0, "%.0f\n", wpt->power); } - gtc_write_xml(-1, "\n", wpt->cadence); + gtc_write_xml(-1, "\n"); gtc_write_xml(-1, "\n"); } @@ -359,7 +359,7 @@ gtc_fake_hdr(void) gtc_write_xml(-1,"\n"); } if (tdata->avg_cad) { - gtc_write_xml(0, "%.1f\n", tdata->avg_cad); + gtc_write_xml(0, "%d\n", tdata->avg_cad); } gtc_write_xml(0, "Active\n"); diff --git a/gpsbabel/jeeps/gpsapp.cc b/gpsbabel/jeeps/gpsapp.cc index b21761b7b..4c57544ef 100644 --- a/gpsbabel/jeeps/gpsapp.cc +++ b/gpsbabel/jeeps/gpsapp.cc @@ -6670,7 +6670,10 @@ void GPS_D1011b_Get(GPS_PLap* Lap, UC* p) return; case pD1011: case pD1015: - (*Lap)->avg_cadence = *p++; + if (*p != 0xff) { + (*Lap)->avg_cadence = *p; + } + *p++; (*Lap)->trigger_method = *p++; break; default: @@ -7183,7 +7186,10 @@ void GPS_D1007_Get(GPS_PCourse_Lap* clp, UC* p) (*clp)->avg_heart_rate = *p++; (*clp)->max_heart_rate = *p++; (*clp)->intensity = *p++; - (*clp)->avg_cadence = *p++; + if (*p != 0xff) { + (*clp)->avg_cadence = *p; + } + *p++; return; } @@ -7232,7 +7238,7 @@ void GPS_D1007_Send(UC* data, GPS_PCourse_Lap clp, int32* len) *p++ = clp->intensity; - *p++ = clp->avg_cadence; + *p++ = clp->avg_cadence > 0 ? clp->avg_cadence : 0xff; *len = p-data; -- 2.30.2